<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function copyObj(obj){
            let newObj = JSON.stringify(obj);
           
            objClone = JSON.parse(newObj);


            return objClone;

            // return objClone.JSON.stringify(JSON.parse(obj));
            // return newObj
           
        }
        let a = [1,2,3,4],
            b = copyObj2(a);
        a[0]=0;
        console.log(a,b);




         function copyObj2(obj){
              let obj2 = JSON.stringify(obj);
              let objClone = JSON.parse(obj2);
              return objClone;
         }

        

        function copyObj3(obj){
            let objClone = JSON.parse(JSON.stringify(obj)) ;
            return objClone;
        }
         a = [1,2,3,4];
        b = copyObj3(a);
        b[0] = 2;
        console.log(a,b);

    </script>
</body>
</html>